#define _CRT_SECURE_NO_WARNINGS


//1.

/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     struct TreeNode *left;
 *     struct TreeNode *right;
 * };
 */


bool isSameTree(struct TreeNode* p, struct TreeNode* q) {
    if (p == NULL && q == NULL)
        return true;
    if (!p || !q)
        return false;
    if (p->val != q->val)
        return false;
    return isSameTree(p->left, q->left)
        && isSameTree(p->right, q->right);
}
bool isSubtree(struct TreeNode* root, struct TreeNode* subRoot) {
    if (root == NULL)
        return false;
    if (root->val == subRoot->val)
    {
        if (isSameTree(root, subRoot) == true)
            return true;
    }
    return isSubtree(root->left, subRoot)
        || isSubtree(root->right, subRoot);
}


// 2

class Solution {
public:
    string addStrings(string num1, string num2) {
        int end1 = num1.size() - 1;
        int end2 = num2.size() - 1;
        string str;
        str.reserve(max(num1.size(), num2.size()) + 1);
        int carry = 0;
        while (end1 >= 0 || end2 >= 0)
        {
            int val1 = end1 >= 0 ? num1[end1] - '0' : 0;
            int val2 = end2 >= 0 ? num2[end2] - '0' : 0;

            int ret = val1 + val2 + carry;
            carry = ret / 10;
            ret %= 10;

            str += ('0' + ret);
            end1--;
            end2--;
        }
        if (carry == 1)
            str += '1';
        reverse(str.begin(), str.end());
        return str;
    }
};